package com.application.race.manage.action;

import com.application.race.manage.player.Player;
	public class Action
	{

		
		private static final int LEFT =0x00000001;
		private static final int RIGHT=0x00000002;
		private static final int UP   =0x00000004;
		private static final int DOWN =0x00000008;
		
		private static final int RELASE_ACC =0x00000010;
		private static final int BRAKE      =0x00000020;
		private static final int BRAKE_UP   =0x00000040;
		private static final int BRAKE_DOWN =0x00000080;
		
		
	    private Player actor;
	    int acode;
		public Action(Player actor)
		{
			this.actor=actor;
		}
	 
		public void parseActionCode(int acode){
			if((acode&LEFT)>0)
				actor._left=true;
			else
				actor._left=false;
				
			if((acode&RIGHT)>0)
				actor._right=true;
		    else
		        actor._right=false;
		        
			if((acode&UP)>0)
				actor._up=true;
			else
			    actor._up=false;
			    
			if((acode&DOWN)>0)
				actor._down=true;
			else
				actor._down=false;
				
			if((acode&RELASE_ACC)>0)
				actor._relaseAccelerator=true;
			else 
				actor._relaseAccelerator=false;
				
			if((acode&BRAKE)>0)
				actor._brake=true;
			else 
				actor._brake=false;
				
			if((acode&BRAKE_UP)>0)
				actor._brake_up=true;
			else 
			 	actor._brake_up=false;
			 	
			if((acode&BRAKE_DOWN)>0)
				actor._brake_down=true;
			else 
		  		actor._brake_down=false;	
		}
		public int getCurentActionCode(){
			acode=0;
			if(actor._left)
				acode=acode|LEFT;
			if(actor._right)
				acode=acode|RIGHT;
			if(actor._up)
				acode=acode|UP;
			if(actor._down)
				acode=acode|DOWN;
			if(actor._relaseAccelerator)
				acode=acode|RELASE_ACC;
			if(actor._brake)
				acode=acode|BRAKE;
			if(actor._brake_up)
				acode=acode|BRAKE_UP;
			if(actor._brake_down)
				acode=acode|BRAKE_DOWN;
 
			return acode;
		}	
	}
